package com.gs.wechatdemo.activity;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import androidx.annotation.RequiresApi;

import com.gs.wechatdemo.R;
import com.gs.wechatdemo.constant.AllConstants;
import com.gs.wechatdemo.service.SignalRService;
import com.gs.wechatdemo.util.PermissionUtil;
import com.gs.wechatdemo.util.SPUtil;

public class LoginActivity extends Activity {

    private EditText etMyId;

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        PermissionUtil.addPermission(this,
                new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE},
                AllConstants.RECORD_AUDIO);
        etMyId = findViewById(R.id.et_my_id);
        etMyId.setText(SPUtil.getInstance().getString(AllConstants.ID));
        findViewById(R.id.btn_login).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SPUtil.getInstance().putString(AllConstants.ID, etMyId.getText().toString());
                startService(new Intent(LoginActivity.this, SignalRService.class));
                startActivity(new Intent(LoginActivity.this, ContactListActivity.class));
                finish();
            }
        });
    }
}